package com.ruoyi.wxorali.utils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

public class AliYunUtil {
    /**
     * 解析JSON
     */
    public static Map<String,Boolean> resolvingJSON(JSONArray array){
        Map<String,Boolean>map = new HashMap<>();
        for (int i = 0; i <array.size(); i++) {
            JSONObject object = array.getJSONObject(i);
            if(ObjectUtils.isNotEmpty(object)){
                if(object.containsKey("results")){
                    JSONArray results = object.getJSONArray("results");
                    if(results.size() > 0){
                        for (int j = 0; j <results.size(); j++) {
                            JSONObject resobj = results.getJSONObject(i);
                            if(resobj.containsKey("subResults")){
                                JSONArray objarray = resobj.getJSONArray("subResults");
                                for (int k = 0; k < objarray.size(); k++) {
                                    JSONObject obj = objarray.getJSONObject(k);
                                    if(obj.containsKey("suggestion") && ("block".equals(obj.get("suggestion"))|| "review".equals(obj.get("suggestion")))){
                                        map.put(resobj.get("dataId").toString(),false);
                                    }
                                }


                            }
                        }
                    }
                }

            }
        }
        return map;
    }
}
